import type { PageParam, PageResult } from '#/api/base';

import { requestClient } from '#/api/request';

export namespace RoleApi {
  /** 角色信息 */
  export interface Role {
    id?: number;
    systemId: number;
    title: string;
    status: number;
    remark?: string;
    isDeleted?: number;
    createTime?: string;
    updateTime?: string;
    handler?: number;
    handlerName: string;
    menuIds?: number[];
  }

  /** 角色列表查询参数 */
  export interface RoleListParams extends PageParam {
    systemId?: number;
    title?: string;
    status?: number;
  }
}

/** 查询角色列表 */
export function getRoleList(params: RoleApi.RoleListParams) {
  return requestClient.get<PageResult<RoleApi.Role>>('/role/list', {
    params,
  });
}

/** 查询角色详情 */
export function getRole(id: number) {
  return requestClient.get<RoleApi.Role>(`/role/info?id=${id}`);
}

/** 新增角色 */
export function createRole(data: RoleApi.Role) {
  return requestClient.post('/role/create', data);
}

/** 修改角色 */
export function updateRole(data: RoleApi.Role) {
  return requestClient.put('/role/update', data);
}

/** 删除角色 */
export function deleteRole(id: number) {
  return requestClient.delete(`/role/delete?id=${id}`);
}
